package com.rui1024.dao.impl;

import com.rui1024.dao.MenuDao;
import com.rui1024.pojo.Diary;
import com.rui1024.pojo.Menu;
import com.rui1024.util.DateUtil;
import com.rui1024.util.PageUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class MenuDaoImpl implements MenuDao {

    public List<Menu> readMenu(Connection con) throws Exception { // 定义了readMenu()方法操作从数据库读取菜单出来
        String sql = "select * from menu";
        List<Menu> list = new ArrayList<Menu>();
        PreparedStatement pstmt = con.prepareStatement(sql);
        ResultSet rs = pstmt.executeQuery();

        while (rs.next()) {
            int id = -1;//购物车功能添加的
            if (rs.getObject("Id") != null) {
                id = rs.getInt("Id");
            } else {
                id = -1;
            }
            String name = rs.getString("name");
            String chef = rs.getString("chef");
            int price = rs.getInt("price");
            Menu ml = new Menu(id, name, chef, price);
            list.add(ml);
        }
        return list;

    }



}
